using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using System;
using System.Collections.Generic;
using System.Windows;
namespace MicroMsg.UI.UserContrl
{
	public class UIDelayService
	{
		private static UIDelayService mService;
		private object RefreshArrayLock = new object();
		private List<UIAction> RefreshItems = new List<UIAction>();
		private UIDelayService()
		{
		}
		public static UIDelayService getInstance()
		{
			if (UIDelayService.mService == null)
			{
				UIDelayService.mService = new UIDelayService();
			}
			return UIDelayService.mService;
		}
		public void Push(UIAction action)
		{
			if (action == null)
			{
				return;
			}
			lock (this.RefreshArrayLock)
			{
				this.RefreshItems.Add(action);
			}
		}
		public void DoDelayAction()
		{
			this.Pop();
		}
		private BasePage getBasePage()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			if (phoneApplicationFrame == null)
			{
				return null;
			}
			return phoneApplicationFrame.get_Content() as BasePage;
		}
		private void Pop()
		{
			if (this.RefreshItems.get_Count() <= 0)
			{
				return;
			}
			BasePage basePage = this.getBasePage();
			if (basePage == null)
			{
				return;
			}
			basePage.get_Dispatcher().BeginInvoke(delegate
			{
				lock (this.RefreshArrayLock)
				{
					if (this.RefreshItems.get_Count() <= 0)
					{
						return;
					}
					UIAction uIAction = this.RefreshItems.get_Item(0);
					uIAction();
					this.RefreshItems.RemoveAt(0);
				}
				this.Pop();
			});
		}
	}
}
